// test.ts

// 导入 AssemblyScript 标准库
//import { i32, Array, id, Memory } from "@assemblyscript/std/assembly";
import { i32, Array, Memory } from "node_modules/assemblyscript/lib/loader";
// 导出内存

export const memory: Memory = new Memory({ initial: 1, maximum: 4 });

// 函数1：无参数传入传出，for循环1加到1000赋值数组2，作为baseline
export function baselineTest(): void {
    let array2: Array<i32> = new Array<i32>(100000);
    for (let i = 0; i < 100000; i++) {
        array2[i] = i + 1;
    }
}

// 函数2：无参数传入，for循环1到1000赋值给数组2，传出数组2
export function noInputWithOutput(): Array<i32> {
    let array2: Array<i32> = new Array<i32>(100000);
    for (let i = 0; i < 100000; i++) {
        array2[i] = i + 1;
    }
    return array2;
}

// 函数3：传入数组1，for循环1到1000赋值给数组2，这一步目的是控制变量，传出数组2
export function withInputAndOutput(array1: Array<i32>): Array<i32> {
    let sum = array1[3];
    let array2: Array<i32> = new Array<i32>(100000);

    for (let i = 0; i < 100000; i++) {
        array2[i] = i + 1;
    }
    return array2;
}

// 函数4：传入数组1，for循环1到1000赋值给数组2，这一步目的是控制变量，无返回值
export function withInputNoOutput(array1: Array<i32>): void {
    let sum = array1[3];
    let array2: Array<i32> = new Array<i32>(100000);
    for (let i = 0; i < 100000; i++) {
        array2[i] = i + 1;
    }
}

